package march.finalmarch22.march02;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class Reducer02 extends Reducer<Text, Text,Text,Text> {
    @Override
    protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {

        //每次循环不同课程都需要置0
        int max = 0;
        //循环该课程
        for (Text value : values) {
            String[] split = value.toString().split("\\|");
            String ave = split[2];
            String[] split1 = ave.split(",");

            for (String s : split1) {
                int temp = Integer.parseInt(s);
                if(temp>max){
                    max = temp;
                }
            }
        }
        String res = key.toString()+","+max;
        context.write(new Text(res),new Text(String.valueOf(max)));
    }
}
